package com.example.projectmanagement.repository.study;

import com.example.projectmanagement.model.study.Lesson;
import com.example.projectmanagement.model.study.Module;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LessonRepository extends JpaRepository<Lesson, Long> {
    
    @Query("SELECT l FROM Lesson l WHERE l.module.course.id = :courseId")
    List<Lesson> findByCourseId(@Param("courseId") Long courseId);
    
    @Query("SELECT l FROM Lesson l WHERE l.lessonType = 'VIDEO'")
    List<Lesson> findVideoLessons();
    
    void deleteByModule(Module module);
    
    @Query("SELECT l FROM Lesson l WHERE l.module.id = :moduleId ORDER BY l.displayOrder ASC")
    List<Lesson> findByModuleIdOrderByDisplayOrderAsc(@Param("moduleId") Long moduleId);
    
    @Query("SELECT COUNT(l) FROM Lesson l WHERE l.module.course.id = :courseId")
    Long countByCourseId(@Param("courseId") Long courseId);
}